#ifndef _TASK_MANAGER_H_
#define _TASK_MANAGER_H_

#include <string>
#include <queue>
#include <map>
#include <iostream>

#include "ObjectPool.h"
#include "pevents.h"
#if (defined _WIN64) || (defined _MSC_VER)
#include <windows.h>
#include <windef.h>
typedef unsigned int Hevent;
#endif




typedef struct _EntryResource
{
	std::string name_;
	int start_;
	int end_;

}EntryResource;

class TaskDispatcher
{
public:
	TaskDispatcher();
	~TaskDispatcher();
	/////////////////////   main interface of this class  ////////////////////////////
	int Init();
	int start(); //only for start the monitoring thread
	int run();
	int stop();

	int processed_entry_num;
	int error_entry_num;
	static const int nMinThread_num = 10;
protected:
	//Here we use the monitor<-->worker mode to monitor and manage all workers' jobs
	int Monitor() //this is the thread function
	{
		while (true)
		{	
			

		}

		return 0;
	}
	int Worker(int entry_start, int entry_end){
		//////////////////////////////////////////////////////////////////////////
		if (entry_start < 0 || entry_end <= 0){
			std::cout << "start point or end point is not correct\n";
			return -1;
		}

		return 0;
	}
private:
	std::queue<EntryResource> waiting_queue_;
	std::map <int, int> running_registered_threads_;
	ObjectPool<int> theads_pool_;
	ObjectPool<neosmart::neosmart_event_t> events_pool_;



};




int TaskDispatcher::Init(){
	return 0;
}


TaskDispatcher::TaskDispatcher() :processed_entry_num(0), error_entry_num(0)
{
}


TaskDispatcher::~TaskDispatcher()
{
}

int TaskDispatcher::start(){

	return 0;
}


int TaskDispatcher::run(){
	int ret = 0;
	while (true)
	{

	}
	return ret;
}


int TaskDispatcher::stop(){
	int ret = 0;
	///////////////////////HERE WE RECOVER RESOURCES //////////////////////////////

	///////////////////////FOR SOME RESONES AND CONDTIONS /////////////////////////////

	///////////////////////RELEASE SOME RESOURCES /////////////////////

	return ret;
}


#endif